package com.tech.cloudapp.db.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tech.cloudapp.po.UserAnswerResultParamPO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserAnswerResultMapper extends BaseMapper<UserAnswerResultParamPO.UserAnswerResultPO> {

     @Select("select " +
             "sum(if(is_right = 1,1,0)) 'right'," +
             "sum(if(is_right = 0,1,0)) 'fail'," +
             "count(1) 'total'," +
             "format((max(answer_time)-min(answer_time))/(1000*60),2) 'taketime'" +
             "from question_user_answer qua where classify_id = #{classifyId} and paper_id = #{paperId} " +
             " and user_id = #{userId} group by classify_id,paper_id;")
     UserAnswerResultParamPO.UserAnswerResultPO result(UserAnswerResultParamPO userAnswerResultParamPO);


     @Select("select " +
             "score ,ui.nick_name as nickName,ui.mobilephone " +
             "from (select user_id ,sum(score) as score from question_user_all qua group by user_id) t " +
             "inner join user_info ui on t.user_id = ui.user_id order by score limit 10 ")
     List<UserAnswerResultParamPO.UserScoreSortResultPO> scoreRange();
}
